import 'dart:collection';

import 'package:dio/dio.dart';
import 'package:tender_flutter/constant/api_path.dart';
import 'package:tender_flutter/http/api_response.dart';
import 'package:tender_flutter/http/http_utils.dart';

class ApiLogin {
  /// 用户登录
  static Future userLogin<T>({String authToken}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["token"] = authToken;
      final response = await HttpUtils.postForm(ApiPath.login, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 手机号码登录
  static Future phoneLogin<T>({String phone, String code}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["phone"] = phone;
      params["code"] = code;
      final response =
          await HttpUtils.postForm(ApiPath.phoneLogin, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }

  /// 发送验证码
  static Future sendCode<T>(
      {String captcha, String phone, String mobileID}) async {
    try {
      Map<String, dynamic> params = HashMap();
      params["captcha"] = captcha;
      params["mobileID"] = mobileID;
      params["phone"] = phone;
      final response = await HttpUtils.get(ApiPath.sendCode, params: params);
      return ApiResponse<T>.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    }
  }
}
